<?php /*
Plugin Name: WP Social Share Privacy
Plugin URI: http://fkblog.de/wp/plugins/wp-social-share-privacy/
Description: <a href="http://www.heise.de/extras/socialshareprivacy/" title="jQuery Plug-In socialshareprivacy">jQuery Plug-In socialshareprivacy</a> from Heise.de for WordPress.
Version: 1.0.0
Author: Fabian K&uuml;nzel
Author URI: http://fkblog.de
License: MIT License (http://www.opensource.org/licenses/mit-license.php) 
*/



// create custom plugin settings menu
add_action('admin_menu', 'socialshareprivacy_create_menu');
function socialshareprivacy_create_menu() {

	//create new top-level menu
  add_submenu_page('options-general.php','Social Share Privacy', 'Social Share Privacy','administrator', __FILE__, 'socialshareprivacy_settings_page' );
	//call register settings function
	add_action( 'admin_init', 'register_socialshareprivacy_settings' );
}


function register_socialshareprivacy_settings() {
	//register our settings
	// Facebook Settings
	register_setting( 'socialshareprivacy-group', 'facebook_status' );
	register_setting( 'socialshareprivacy-group', 'facebook_perma_option' );
	register_setting( 'socialshareprivacy-group', 'facebook_app_id' );
	register_setting( 'socialshareprivacy-group', 'facebook_display_name' );
	register_setting( 'socialshareprivacy-group', 'facebook_referrer_track' );
	register_setting( 'socialshareprivacy-group', 'facebook_display_name' );
	
	// Twitter Settings
	register_setting( 'socialshareprivacy-group', 'twitter_status' );
	register_setting( 'socialshareprivacy-group', 'twitter_perma_option' );
	register_setting( 'socialshareprivacy-group', 'twitter_display_name' );
	register_setting( 'socialshareprivacy-group', 'twitter_referrer_track' );
	register_setting( 'socialshareprivacy-group', 'twitter_display_name' );
	
	// Google+ Settings
	register_setting( 'socialshareprivacy-group', 'googlePlus_status' );
	register_setting( 'socialshareprivacy-group', 'googlePlus_perma_option' );
	register_setting( 'socialshareprivacy-group', 'googlePlus_display_name' );
	register_setting( 'socialshareprivacy-group', 'googlePlus_referrer_track' );
	register_setting( 'socialshareprivacy-group', 'googlePlus_display_name' );
}

// Uninstall options
function socialshareprivacy_uninstall() {
  if ( function_exists('current_user_can') && current_user_can('manage_options') ) {
  	delete_option('facebook_status');
		delete_option('facebook_perma_option');
		delete_option('facebook_app_id');
		delete_option('facebook_display_name');
		delete_option('facebook_referrer_track');
		delete_option('facebook_display_name');
		delete_option('twitter_status');
		delete_option('twitter_perma_option');
		delete_option('twitter_display_name');
		delete_option('twitter_referrer_track');
		delete_option('twitter_display_name');
		delete_option('googlePlus_status');
		delete_option('googlePlus_perma_option');
		delete_option('googlePlus_display_name');
    delete_option('googlePlus_referrer_track');
    delete_option('googlePlus_display_name');
  } else {
		wp_die('<p>'.__('Du hast nicht ausreichend Rechte um die Einstellungen zu &auml;ndern.', 'socialshareprivacy').'</p>');
	}
}

function socialshareprivacy_settings_page() {

	if ( isset($_POST['stage']) && ('update' == $_POST['stage']) ) {
		$message_export = '<br class="clear"><div class="updated"><p>';
		$message_export.= __('Einstellungen wurden aktualisiert!', 'socialshareprivacy');
		$message_export.= '</p></div>';
	}
	
  if ( (isset($_POST['socialshareprivacy_deinstall_yes'])) && (isset($_POST['stage']) && $_POST['stage'] == 'uninstall') ) {
		socialshareprivacy_uninstall();
		$message_export = '<br class="clear"><div class="updated"><p>';
		$message_export.= __('Social-2-Click Einstellungen wurden deinstalliert!', 'socialshareprivacy');
		$message_export.= '</p></div>';
	}
?>
<div class="wrap">
<h2>Social Share Privacy</h2>
<?php echo $message_export; ?>

		<div id="poststuff" class="ui-sortable">
			<div class="postbox closed" >
				<h3><?php _e('Information zum Plugin', 'socialshareprivacy') ?></h3>
				<div class="inside">
					<p><strong>2 Klicks für mehr Datenschutz</strong></p>
					<p>Das jQuery Plugin <em>Social Share Privacy</em> stammt von <a href="http://www.heise.de/" title="Heise Online">Heise Online</a> und wurde von <a href="http://fkblog.de/"" title="Fabian K&uuml;nzel">Fabian K&uuml;nzel</a> an WordPress angepasst.</p>
          <p>Mit dem <em>Social Share Privacy</em> Plugin verhindert Ihr, das schon beim Aufruf eurer Webseite, Daten an die Socialmedia Plattformen, in die USA gesendet werden.<br />MIt diesem Plugin gebt Ihr euren Besuchern selbst die Wahl, ob er damit einverstanden ist und sch&uuml;tzt somit die Privatsp&auml;re derjenigen, die dieses nicht wollen.</p>
          <p>Auch k&ouml;nnt Ihr mit Hilfe dieses Plugins ein schritt in richtung Datenschutz Sicherheit gehen, heise.de hat hierzu einen Artikel; <em><a href="http://www.heise.de/security/artikel/Das-verraet-Facebooks-Like-Button-1230906.html" title="Das Like-Problem">Das Like-Problem</a> Ver&ouml;ffentlicht, in dem &uuml;ber das Datenschutz Problem mit den Social Media Plugins eingegangen wird.</p>
          <p>Das Orginale jQuery Plugin k&ouml;nnt Ihr unter <a href="http://www.heise.de/extras/socialshareprivacy/" title="jQuery Plug-In socialshareprivacy – Dokumentation">http://www.heise.de/extras/socialshareprivacy/</a> Downloaden
				</div>
			</div>
		</div>

<form method="post" action="options.php">
    <?php settings_fields( 'socialshareprivacy-group' ); ?>
    <?php // do_settings( 'baw-settings-group' ); ?>
    <h3>Facebook</h3>
    <table class="form-table" id="facebook">
    
        <tr valign="top">
          <th scope="row"><strong>Status</strong></th>
          <?php $facebook_status = get_option('facebook_status'); ?>
          <td>
            An <input type="radio" name="facebook_status" value="on" <?php if ($facebook_status == on ) echo 'checked="checked"'; ?> /> Aus <input type="radio" name="facebook_status" value="off" <?php if ($facebook_status == off ) echo 'checked="checked"'; ?> />
            <br /><small>Der User hat Facebook zur Auswahl</small>
          </td>      
        </tr>

        <tr valign="top">
          <th scope="row"><strong>Dauerhaft Aktiv</strong></th>
          <?php $facebook_perma_option = get_option('facebook_perma_option'); ?>
          <td>
            An <input type="radio" name="facebook_perma_option" value="on" <?php if ($facebook_perma_option == on ) echo 'checked="checked"'; ?> /> Aus <input type="radio" name="facebook_perma_option" value="off" <?php if ($facebook_perma_option == off ) echo 'checked="checked"'; ?> />
            <br /><small>Der User hat die Option sich Facebook dauerhaft einblenden zu lassen (mittels Cookie)</small>
          </td>      
        </tr>
        
        <tr valign="top">
          <th scope="row"><strong>Facebook App-ID</strong></th>
          <td>
            <input type="text" name="facebook_app_id" value="<?php echo get_option('facebook_app_id'); ?>" />
            <br /><small>Facebook App-ID; Sie ist nötig um den Empfehlen-Button von Facebook nutzen zu können.<br />Ist sie nicht angegeben, wird dem User Facebook trotz <code>'status' : 'on'</code> nicht angeboten.<br />In der JavaScript-Konsole wird dem Entwickler ein entsprechender Hinweis ausgegeben.</small>
          </td>
        </tr>
         
        <tr valign="top">
          <th scope="row"><strong>Anzeige Name</strong></th>
          <td>
            <input type="text" name="facebook_display_name" value="<?php echo get_option('facebook_display_name'); ?>" />
            <br /><small>Schreibweise des Service in den Optionen</small>
          </td>
        </tr>
        
        <tr valign="top">
          <th scope="row"><strong>Referrer</strong></th>
          <td>
            <input type="text" name="facebook_referrer_track" value="<?php echo get_option('facebook_referrer_track'); ?>" />
            <br /><small>Wird ans Ende der URL gehängt, kann zum Tracken des Referrers genutzt werden</small>  
          </td>
        </tr>
              
    </table>


    <h3>Twitter</h3>
    <table class="form-table" id="twitter">
    
        <tr valign="top">
          <th scope="row"><strong>Status</strong></th>
          <?php $twitter_status = get_option('twitter_status'); ?>
          <td>
            An <input type="radio" name="twitter_status" value="on" <?php if ($twitter_status == on ) echo 'checked="checked"'; ?> /> Aus <input type="radio" name="twitter_status" value="off" <?php if ($twitter_status == off ) echo 'checked="checked"'; ?> />
            <br /><small>Der User hat Twitter zur Auswahl</small>  
          </td>      
        </tr>

        <tr valign="top">
          <th scope="row"><strong>Dauerhaft Aktiv</strong></th>
          <?php $twitter_perma_option = get_option('twitter_perma_option'); ?>
          <td>
            An <input type="radio" name="twitter_perma_option" value="on" <?php if ($twitter_perma_option == on ) echo 'checked="checked"'; ?> /> Aus <input type="radio" name="twitter_perma_option" value="off" <?php if ($twitter_perma_option == off ) echo 'checked="checked"'; ?> />
            <br /><small>Der User hat die Option sich Facebook dauerhaft einblenden zu lassen (mittels Cookie)</small>
          </td>      
        </tr>
         
        <tr valign="top">
          <th scope="row"><strong>Anzeige Name</strong></th>
          <td>
            <input type="text" name="twitter_display_name" value="<?php echo get_option('twitter_display_name'); ?>" />
            <br /><small>Schreibweise des Service in den Optionen</small>
          </td>
        </tr>
        
        <tr valign="top">
          <th scope="row"><strong>Referrer</strong></th>
          <td> 
            <input type="text" name="twitter_referrer_track" value="<?php echo get_option('twitter_referrer_track'); ?>" />
            <br /><small>Wird ans Ende der URL gehängt, kann zum Tracken des Referrers genutzt werden</small>
          </td>
        </tr>
              
    </table>
 
    <h3>Google+</h3>
    <table class="form-table" id="google">
    
        <tr valign="top">
          <th scope="row"><strong>Status</strong></th>
          <?php $googlePlus_status = get_option('googlePlus_status'); ?>
          <td>
            An <input type="radio" name="googlePlus_status" value="on" <?php if ($googlePlus_status == on ) echo 'checked="checked"'; ?> /> Aus <input type="radio" name="googlePlus_status" value="off" <?php if ($googlePlus_status == off ) echo 'checked="checked"'; ?> />
            <br /><small>Der User hat Google+ zur Auswahl</small>  
          </td>      
        </tr>

        <tr valign="top">
          <th scope="row"><strong>Dauerhaft Aktiv</strong></th>
          <?php $googlePlus_perma_option = get_option('googlePlus_perma_option'); ?>
          <td>
            An <input type="radio" name="googlePlus_perma_option" value="on" <?php if ($googlePlus_perma_option == on ) echo 'checked="checked"'; ?> /> Aus <input type="radio" name="googlePlus_perma_option" value="off" <?php if ($googlePlus_perma_option == off ) echo 'checked="checked"'; ?> />
            <br /><small>Der User hat die Option sich Facebook dauerhaft einblenden zu lassen (mittels Cookie)</small>  
          </td>      
        </tr>
         
        <tr valign="top">
          <th scope="row"><strong>Anzeige Name</strong></th>
          <td>
            <input type="text" name="googlePlus_display_name" value="<?php echo get_option('googlePlus_display_name'); ?>" />
            <br /><small>Schreibweise des Service in den Optionen</small>
          </td>
        </tr>
        
        <tr valign="top">
          <th scope="row"><strong>Referrer</strong></th>
          <td>
            <input type="text" name="googlePlus_referrer_track" value="<?php echo get_option('googlePlus_referrer_track'); ?>" />
            <br /><small>Wird ans Ende der URL gehängt, kann zum Tracken des Referrers genutzt werden</small>
          </td>
        </tr>
              
    </table> 
   
    <p class="submit">
    <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
    <input type="hidden" name="stage" value="update" />
    </p>

</form>

    <div id="poststuff" class="ui-sortable">
			<div class="postbox closed" >
				<h3><?php _e('Einstellungen deinstallieren', 'socialshareprivacy') ?></h3>
				<div class="inside">
					<form name="form2" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?page=socialshareprivacy/socialshareprivacy.php">
						<p>Der Button inkl. aktive Checkbox l&ouml;scht alle Einstellungen des Plugins Social Share Privacy. Bitte nutze ihn, <strong>bevor</strong> das Plugin deaktiviert wird.<br /><strong>Achtung: </strong>Du kannst dies nicht r&uuml;ckg&auml;ngig machen!</p>
						<p id="submitbutton">
							<input type="submit" name="Submit_uninstall" value="<?php _e('Uninstall Options &raquo;', 'socialshareprivacy') ?>" class="button-secondary" />
							<input type="checkbox" name="socialshareprivacy_deinstall_yes" value="socialshareprivacy_deinstall" />
							<input type="hidden" name="stage" value="uninstall" />
						</p>
					</form>
				</div>
			</div>
		</div>

		<script type="text/javascript">
		<!--
		<?php if ( version_compare( substr($wp_version, 0, 3), '2.7', '<' ) ) { ?>
		jQuery('.postbox h3').prepend('<a class="togbox">+</a> ');
		<?php } ?>
		jQuery('.postbox h3').click( function() { jQuery(jQuery(this).parent().get(0)).toggleClass('closed'); } );
		jQuery('.postbox.close-me').each(function(){
			jQuery(this).addClass("closed");
		});
		//-->
		</script>
</div>
<?php } 

// Output for Template

function socialshareprivacy_scripts() {
   $socialshareprivacy_url = trailingslashit( get_bloginfo('wpurl') ).PLUGINDIR.'/'. dirname( plugin_basename(__FILE__) );
   wp_enqueue_script('socialshareprivacy', $socialshareprivacy_url.'/js/jquery.socialshareprivacy.js', array('jquery'), '1.4.2');
} add_action('wp_print_scripts', 'socialshareprivacy_scripts');
 
function socialshareprivacy_scripttag() {
   $socialshareprivacy_url = trailingslashit( get_bloginfo('wpurl') ).PLUGINDIR.'/'. dirname( plugin_basename(__FILE__) );
echo "
  <script type=\"text/javascript\">
jQuery(document).ready(function($){
	if($('#social_bookmarks')){
		$('#social_bookmarks').socialSharePrivacy({
		    'services' : {
                'facebook' : {
                    'status'            : '". get_option('facebook_status') ."',
                    'app_id'            : '". get_option('facebook_app_id') ."',
                    'dummy_img'         : '". $socialshareprivacy_url ."/images/dummy_facebook.png',
                    'perma_option'      : '". get_option('facebook_perma_option') ."',
                    'display_name'      : '". get_option('facebook_display_name') ."',
                    'referrer_track'    : '". get_option('facebook_referrer_track') ."',
                }, 
                'twitter' : {
                    'status'            : '". get_option('twitter_status') ."',
                    'dummy_img'         : '". $socialshareprivacy_url ."/images/dummy_twitter.png',
                    'perma_option'      : '". get_option('twitter_perma_option') ."',
                    'display_name'      : '". get_option('twitter_display_name') ."',
                    'referrer_track'    : '". get_option('twitter_referrer_track') ."',
                },
                'gplus' : {
                    'status'            : '". get_option('googlePlus_status') ."',
                    'dummy_img'         : '". $socialshareprivacy_url ."/images/dummy_gplus.png',
                    'perma_option'      : '". get_option('googlePlus_perma_option') ."',
                    'display_name'      : '". get_option('googlePlus_display_name') ."',
                    'referrer_track'    : '". get_option('googlePlus_referrer_track') ."',
                }
            },
            'cookie_domain'     : '". get_bloginfo('wpurl') ."',
            'css_path'          : '". $socialshareprivacy_url ."/socialshareprivacy.css'
		}); 
	}
});
  </script>";
} add_action('wp_head', 'socialshareprivacy_scripttag'); 

function socialshareprivacy_css() {       
$socialshareprivacy_url = trailingslashit( get_bloginfo('wpurl') ).PLUGINDIR.'/'. dirname( plugin_basename(__FILE__) );
  wp_enqueue_style('socialshareprivacy', $socialshareprivacy_url.'/socialshareprivacy.css');
} add_action('wp_print_styles', 'socialshareprivacy_css');
  
function socialshareprivacy() {
    echo '<div id="social_bookmarks"></div>';
}
?>